import { message, Select } from "antd";
import http from "../../utils/http.js";
export default {
    //频到数组
    channels: [],
    //查询所有频道
    async getAllChannel() {
        http({
            url: '/admin/channel/showChannelByPage',
            method: 'post',
            params: {
                page: 1,
                limit: 50
            }
        }).then(res => {
            console.log("1111", res);
            if (res.code === 200) {
                res.data.forEach((el, i) => {
                    el.key = i
                });
                this.channels = res.data
            } else {
                return message.error('服务器异常！')
            }
        }).catch(err => {
            throw err
        }
        )
    },
    SN: [],
    async getAllSN() {
        http({
            url: '/admin/snCode/showSnCode',
            method: 'post',
            params: {
                page: 1,
                limit: 50
            }
        }).then(res => {
            console.log("1111", res);
            if (res.code === 200) {
                res.data.forEach((el, i) => {
                    el.key = i
                });
                this.SN = res.data
            } else {
                return message.error('服务器异常！')
            }
        }).catch(err => {
            throw err
        }
        )
    },
    // ADD:[],
    async getAdd(obj) {
        http({
            url: '/admin/channel/addOrUpdateChannel',
            method: 'post',
            params: {
                channelApp: obj.createtime,
                // channelId:obj.id,
                channelName: obj.name,
                weight: obj.des
            }
        }).then(res => {
            console.log("1111", res);
            if (res.code === 200) {
                this.getAllChannel()
            } else {

                return message.error('服务器异常！')
            }
        }).catch(err => {
            console.log(err);
        }
        )
    },
    // Select:[],
    async getSelect(Select) {
        console.log(Select);
        const arr = Select.map(v => v.channelId)
        http({
            url: '/admin/channel/deleteChannelById',
            method: 'post',
            params: {
                ids: arr
            }
        }).then(res => {
            console.log("1111", res);
            if (res.code === 200) {
                this.getAllChannel()
            } else {
                return message.error('服务器异常！')
            }
        }).catch(err => {
            throw err
        }
        )
    },
    async texTj(snValue, stateTx, telephoneTx, time, geto) {
        // console.log(Select);
        // const arr = Select.map(v => v.channelId)
        http({
            url: '/admin/snCode/showSnCodeByCondition',
            method: 'post',
            params: {
                snCode: snValue,
                snStatus: stateTx,
                bindPhone: telephoneTx,
                // upTime1:time[0],
                // upTime1:time[1],
                // bindTime1:geto[0],
                // bindTime1:geto[1],
            }
        }).then(res => {
            console.log(res);
            if (res.code === 200) {
                // this.getAllChannel()
                res.data.forEach((el, i) => {
                    el.key = i
                });
                this.SN = res.data
            } else {
                return message.error('服务器异常！')
            }
            // console.log(res);
        }).catch(err => {
            throw err
        }
        )
    },
    xiugai(obj,id) {
        http({
            url: '/admin/snCode/addOrUpdateSnCode',
            method: 'post',
            params: {
                id,
                snStatus:obj.snStatus ,
                bindPhone:obj.bindPhone ,
                snCode: obj.snCode,
                bindTime: obj.bindTime,
                upTime:obj.upTime,

            }
        }).then(res => {
            console.log(res);
            if (res.code === 200) {
                // this.getAllChannel()
                this.getAllSN()
            } else {
                return message.error('服务器异常！')
            }
            // console.log(res);
        }).catch(err => {
            throw err
        }
        )
    }

}